﻿using System;
using System.Data;
using System.Collections.Generic;
using ElingOA6_DSJCJ.Model;

namespace ElingOA6_DSJCJ.BLL
{
    
    public class SoftwareEntry
    {
        public SoftwareEntry()
        {
        }
        private DAL.SoftwareEntry softwareEntryDAL = new DAL.SoftwareEntry();
        /// <summary>
        /// 根据公司编号获取软件列表
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>返回软件列表</returns>
        public List<Model.SoftwareEntry> GetModelListByFEntityNo(string entityNo)
        {
            DataSet ds = softwareEntryDAL.GetListByFEntityNo(entityNo);
            return DataTableToList(ds.Tables[0]);
        }

                /// <summary>
        /// 根据公司编号和类别编号获取软件列表
        /// <creator>zhongyl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="fSoftwareCatalogID">类别编号</param>
        /// <returns>返回软件列表</returns>
        public List<Model.SoftwareEntry> GetListByFEntityNoAndFSoftwareCatalogID(string entityNo, string fSoftwareCatalogID,int top)
        {
            DataSet ds = softwareEntryDAL.GetListByFEntityNoAndFSoftwareCatalogID(entityNo, fSoftwareCatalogID, top);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>sunlj</creator>
        /// <date>2013-07-19</date>
        /// </summary>
        /// <param name="softwareEntryID">软件编号</param>
        /// <returns>返回软件对象实体</returns>
        public Model.SoftwareEntry GetModel(decimal softwareEntryID)
        {
            return softwareEntryDAL.GetModel(softwareEntryID);
        }
        /// <summary>
        /// 更新下载次数
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        public void UpdateDownCount(decimal softwareEntryID)
        {
            softwareEntryDAL.UpdateDownCount(softwareEntryID);
        }
        // <summary>
        /// 获得数据列表
        /// <creator>sunlj</creator>
        /// <date>2013-07-16</date>
        /// </summary>
        public List<Model.SoftwareEntry> DataTableToList(DataTable dt)
        {
            List<Model.SoftwareEntry> modelList = new List<Model.SoftwareEntry>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.SoftwareEntry model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = softwareEntryDAL.DataRowToModel(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
    }
}
